package com.xzqwjw.taskmanager.activity;

import com.leaderinfo.model.InfoAdmin;
import com.leaderinfo.utility.Utility;

import com.xzqwjw.taskmanager.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

public class ActivityLogin extends Activity {

  private Button btnLogin;
  private EditText etPsd;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    Utility objUti = new Utility();
    final String strDBFile = objUti.checkDBFile();

    if (strDBFile.startsWith("sorry")) {
      new AlertDialog.Builder(this).setTitle("��Ϣ").setMessage(strDBFile)
          .setPositiveButton("�˳�����", new OnClickListener() {
            @Override
            public void onClick(DialogInterface a0, int a1) {
              android.os.Process.killProcess(android.os.Process
                  .myPid());
            }
          }).show();
    } else {
      setContentView(R.layout.activity_login);
      btnLogin = (Button) this.findViewById(R.id.btnLogin);
      etPsd = (EditText) this.findViewById(R.id.etPswd);

      btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          String strPsd = etPsd.getText().toString();
          strPsd = "000000";

          com.leaderinfo.dao.AdminDao objAdminDAO = new com.leaderinfo.dao.AdminDao(strDBFile);
          InfoAdmin objAdminInfo = objAdminDAO.CheckLogin(strPsd);

          if (objAdminInfo.AID == 0) {
            new AlertDialog.Builder(ActivityLogin.this)
                .setTitle("����").setMessage("������������������룡")
                .setPositiveButton("ȷ��", null).show();
          } else {
            Intent objIT = new Intent(ActivityLogin.this,
                ActivityMain.class);
            objIT.putExtra("AID", objAdminInfo.AID);
            objIT.putExtra("DBFilePath", strDBFile);
            startActivity(objIT);
          }
        }
      });

    }

  }

}
